
import 'babel-polyfill'
import Vue from 'vue'
import router from './router'
import store from './store'
import global from '@/assets/js/global'
import ElementUI from 'element-ui'
import VueVirtualScroller from 'vue-virtual-scroller'
import dayjs from 'dayjs'
import App from './App.vue'
import Video from 'video.js'
import 'video.js/dist/video-js.css'
// 按需引入 echarts 5.x
import echarts from './plugins/echarts'
import { AraleQRCode } from './plugins/arale-qrcode/3.0.5/index.js'

import '@/assets/sass/app.scss'
import '@/assets/sass/customer-table.scss'
import '@/assets/sass/tree.scss'
import '@/assets/iconfont/iconfont' // 保留字体图标的颜色，需要用symbol的方式引用
import '@/assets/theme/index.css'
import 'vue-virtual-scroller/dist/vue-virtual-scroller.css'
import './icons' // icon

const isBetween = require('dayjs/plugin/isBetween')
dayjs.extend(isBetween)

Vue.prototype.$echarts = echarts
Vue.prototype.$video = Video
Vue.prototype.$AraleQRCode = AraleQRCode

Vue.use(global)
Vue.use(ElementUI)
Vue.use(VueVirtualScroller)

Vue.config.productionTip = false

// 解决路由加载问题
router.onError((error) => {
  const pattern = /Loading chunk (\d)+ failed/g
  const isChunkLoadFailed = error.message.match(pattern)
  const targetPath = router.history.pending.fullPath
  console.log('targetPath', targetPath)
  if (isChunkLoadFailed) {
    router.replace(targetPath)
  }
})

window.projectApp = new Vue({
  router,
  store,
  render: (h) => h(App),
}).$mount('#app')

Vue.directive('focus', {
  inserted(el, binding, vnode) {
    // 聚焦元素
    el.querySelector('input').focus()
  },
})
